<template>
	<view class="mainpadding2">
		 <view class="flexcenter xiaohui strongtext" style="margin-top: 300rpx;" v-if="list.total==0">-暂无要分享的好友，你需要关注用户才能分享-</view>
		<view class="margin_top flexbetween" v-for="item in list.data" :key="item.id" @click="jumpzhuye(item.user1.id)"
			v-if="user_id!=item.b_user_id">
			<view class="flexleft" style="width: 73%;">
				<image class="touxiang margin_right2" :src="item.user1.avatar_text" mode=""></image>
				<view class="">
					<view class="sanshier fonweight">{{item.user1.nickname}}</view>
					<view class="xiankuan xiaohui strongtext margin_top1 xiankuan" v-if="item.user1.bio">
						{{item.user1.bio}}</view>
					<view class="xiankuan xiaohui strongtext margin_top1 xiankuan" v-else>这个人很懒，什么也没留下！</view>
				</view>
			</view>
			<view class="dlbtn" @click.stop="sixin(item.b_user_id)">分享</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	import WebSocket from '@/static/websocket.js' //websocket封装
	export default {
		data() {
			return {
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				listid: "",
				type: 1, //1视频分享，2动态分享
				user_id: "",
				websocket:null
			}
		},
		onLoad(options) {
			this.user_id = uni.getStorageSync("user_id")
			this.type = options.type
			this.listid = options.id
			this.init()
			this.$forceUpdate()
		},
		methods: {
			sixin(toid){
				let that = this
				uni.showLoading({
					mask:true,
					title:"分享中"
				})
				httpRequest.request('/api/user/addFriends', 'GET', {
					firend_id:toid
				}).then(res => {
					this.fenxiangFn(toid)
				})
				
			},
			fenxiangFn(toid) { //发送消息
				let system = uni.getSystemInfoSync()
				let version_code = system.appVersionCode
				let platform = system.platform
				httpRequest.request('/webim/Friends_Message/add', 'POST', {
					mine: {
						id: uni.getStorageSync("user_id"),
						content: this.listid,
						data_type: this.type == 1 ? 4 : 5, //1=文字,2=图片,3=视频
					},
					to: {
						id: toid,
						type: "friend"
					},
					client_id: uni.getStorageSync("client_id"),
					version_code,
					platform
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						httpRequest.toast("分享成功")
						setTimeout(() => {
							uni.navigateBack(1)
						}, 800)
					} 
					// else if(res.code==403){
					// 	this.websocketStart()
					// } else{
					// 	httpRequest.toast(res.msg)
					// }
				})
			},
			websocketStart() {
				this.websocket = new WebSocket("wss://kuaixun.yongshunqiyuewangluo.com:8282");
				this.websocket.connect()
				this.websocket.onMessage(result => {
					console.log('app.js收到服务器内容：' + result.data);
				})
			},
			getinfo() {
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					this.userinfo = res.data
				})
			},
			getsystem() {
				let system = uni.getSystemInfoSync()
				let version_code = system.appVersionCode
				let platform = system.platform
				console.error(version_code, platform, system);
				httpRequest.request('/api/index/checkApply', 'GET', {
					platform,
					version_code
				}).then(res => {
					// console.log(version_code, platform, res);
					this.isSH = res.data
					this.dbshow = true
				})
			},
			init(isPage, page) {
				let _this = this
				let url = "/api/user/getUserPageGzIndex"
				let data = {
					page: page || 1,
					limit: _this.limit,
					user_id: uni.getStorageSync("user_id")
				}
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
		}
	}
</script>

<style lang="scss" scoped>
	.dlbtn {
		background: #2361FF;
		border-radius: 44rpx;
		padding: 16rpx 40rpx;
		color: #fff;
		font-size: 24rpx;
	}

	.dhbtn {
		background: #F5F5F5;
		border-radius: 44rpx;
		padding: 16rpx 40rpx;
		color: #333;
		font-size: 24rpx;
	}

	.touxiang {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
	}

	.tab_nav {
		background-color: #fff;
		display: flex;
		justify-content: center;
		align-items: center;
		padding-bottom: 11rpx;
	}

	.tab_nav .navTitle {
		height: 90rpx;
		line-height: 90rpx;
		width: 100%;
		text-align: center;
		font-size: 30rpx;
		font-weight: bold;
		color: #999999;
	}

	.active {
		font-size: 30rpx;
		color: #333333;
		font-weight: bold;
		position: relative;
	}

	.active::after {
		content: "";
		position: absolute;
		width: 36rpx;
		height: 6rpx;
		background: #2361FF;
		border-radius: 3rpx;
		background-size: 100% 100%;
		left: 0rpx;
		right: 0rpx;
		bottom: 0rpx;
		margin: auto;
	}
</style>